package com.ahtcm.tcmlearning.controller;

import com.ahtcm.tcmlearning.dataObject.brushProblem.RateOfLearning;
import com.ahtcm.tcmlearning.dataObject.generateQuestion.GenerateQuestion;
import com.ahtcm.tcmlearning.enums.QuestionRecordTypeEnum;
import com.ahtcm.tcmlearning.model.Medicine;
import com.ahtcm.tcmlearning.service.GenerateProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * @description 记忆斩模块
 * 1, "记忆斩中药模块添加的种类记录"  2, "记忆斩方剂模块添加的种类记录" 3, "记忆斩针灸学模块添加的种类记录"
 * 4, "记忆斩药鉴定模块添加的种类记录" 5, "记忆斩病理学模块添加的种类记录"
 */
@RestController
@RequestMapping("/generateProblem")
public class GenerateProblemController {
    @Autowired
    GenerateProblemService generateProblemService;

    /**
     * @description 获得记忆斩某模块的学习进度
     * @param functionType
     * @param userId
     * @return RateOfLearning:totalNumber:类目总数  completed：进行的类目数（id）  rate:进度百分比
     */
    @GetMapping("getRateOfLearning")
    public RateOfLearning getRateOfLearning(@RequestParam("functionType") Integer functionType, @RequestParam("userId") Integer userId) {
        RateOfLearning rateOfLearning = generateProblemService.getRateOfLearning(functionType, userId);
        return rateOfLearning;
    }

    /**
     * @description 获得记忆斩某模块的下一个需要学习展示的知识要点
     * @param functionType
     * @param
     *
     */
    @GetMapping("getNextTypeDetails")
    public Object getNextTypeDetails(@RequestParam("functionType") Integer functionType, Integer currentTypeId) {
        if (functionType.equals(QuestionRecordTypeEnum.MEDICINE_MODULAR__RECORD.getCode())) {
            return generateProblemService.getNextTypeDetailsForMedicine(currentTypeId);
        }
        if (functionType.equals(QuestionRecordTypeEnum.PRESCRIPTION.getCode())) {
            return generateProblemService.getNextTypeDetailsForPrescription(currentTypeId);
        }
        return null;

    }

    /**
     * @description 用户点击跳过做题，向记录表中添加记录
     * @param userId
     * @param typeId 要跳过的种类id
     * @param dicId 父类id
     * @param functionType
     */
    @GetMapping("skipOverTopic")
    public void skipOverTopic(@RequestParam("userId") Integer userId,@RequestParam("typeId") Integer typeId,@RequestParam("dicId") Integer dicId,@RequestParam("functionType")Integer functionType)
    {
        generateProblemService.skipOverTopic(userId,typeId,dicId,functionType);
    }



    /**
     * @description 用户点击做题题，生成题目
     * @param functionType
     * @param typeId 要产生题目的事物处于表中的id
     * @param dicId 事物处于的种类id
     * @return
     */
    @GetMapping("generateQuestion")
    public List<GenerateQuestion> generateQuestion(@RequestParam("functionType") Integer functionType, @RequestParam("typeId") Integer typeId, @RequestParam("dicId") Integer dicId){
        if (functionType.equals(QuestionRecordTypeEnum.MEDICINE_MODULAR__RECORD.getCode())) {
            return generateProblemService.generateMedicineQuestion(typeId,dicId);
        }
        if (functionType.equals(QuestionRecordTypeEnum.PRESCRIPTION.getCode())) {
            return generateProblemService.generatePrescriptionQuestion(typeId,dicId);
        }
        return null;

    }
    @GetMapping("test")
    public void test(){


    }


}